# coding: utf-8

# 调整微信推送策略后，对工程商的套餐信息中paid_sms_point信息进行补全

import os

import set_env_path     # 请勿删除


from sqlalchemy import create_engine
from sqlalchemy.sql import text


engine = create_engine(
    os.getenv('DATABASE_URL')
    or 'mysql+pymysql://root:@127.0.0.1/wph_www_prod?charset=utf8'
)
conn = engine.connect()


def update_pack_paid_sms_point():
    """
    add by zhouhl 2017-10-16
    """

    update_pack_paid_sms_point_sql = text("""
        update
            pack join(
                select
                    uid,
                    count(*)
                from
                    bill
                where
                    status = 200 and bill.type = 1 and bill.sub_type = 2
                group by
                    uid
            ) as t ON
            pack.uid = t.uid
        set
            pack.paid_sms_point = pack.sms_point;
    """)

    records = conn.execute(update_pack_paid_sms_point_sql)



if __name__ == '__main__':
    update_pack_paid_sms_point()
